﻿using System;
using System.Globalization;
using System.Windows.Data;

namespace CannedHeater.View.Converters
{
    /// <summary>
    /// Converts a temperature (double) into a string.
    /// Temperature will be rounded to 1 decimal.
    /// If no temperature specified (NaN), returns "??"
    /// </summary>
    public class TemperatureConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null) return "??";

            double val = (double) value;

            if (Double.IsNaN(val)) return "??";
            else return Math.Round(val, 1).ToString();
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return null;
        }
    }
}
